﻿
using Android.Content.PM;
using Microsoft.Maui.Platform;
namespace MauiApp1.DeviceServices;
public partial class DeviceOrientationService
{
    private static readonly IReadOnlyDictionary<DisplayOrientation, ScreenOrientation> _androidDisplayOrientationMap =
        new Dictionary<DisplayOrientation, ScreenOrientation>
        {
            [DisplayOrientation.Landscape] = ScreenOrientation.Landscape,
            [DisplayOrientation.Portrait] = ScreenOrientation.Portrait,
        };
    public partial void SetDeviceOrientation(DisplayOrientation displayOrientation)
    {
        var currentActivity = ActivityStateManager.Default.GetCurrentActivity();
        if (currentActivity is not null)
        {
            if (_androidDisplayOrientationMap.TryGetValue(displayOrientation, out ScreenOrientation screenOrientation))
            {
                currentActivity.RequestedOrientation = screenOrientation;
            }
            
        }
    }

    public partial void SetNavBar(bool visi)
    {
        var currentActivity = ActivityStateManager.Default.GetCurrentActivity();
        if(currentActivity is not null)
        {
            if(!visi)
            {
                var opts = Android.Views.SystemUiFlags.HideNavigation  | Android.Views.SystemUiFlags.Fullscreen
                    ;
                currentActivity.Window.DecorView.SystemUiFlags = opts;
                //currentActivity.Window.AddFlags(Android.Views.WindowManagerFlags.TranslucentStatus);
                //currentActivity.Window.AddFlags(Android.Views.WindowManagerFlags.TranslucentNavigation);
                //currentActivity.Window.SetStatusBarColor(Android.Graphics.Color.Transparent);
                //currentActivity.Window.SetNavigationBarColor(Android.Graphics.Color.Transparent);
                
            }
            else
            {
               
                currentActivity.Window.DecorView.SystemUiFlags = Android.Views.SystemUiFlags.LayoutStable;
                //currentActivity.Window.SetNavigationBarColor(Android.Graphics.Color.White);
            }
           
        }
    }
}